package cn.pku.ss.sirx.sna.ib.bean;

import cn.pku.ss.sirx.sna.ib.ReplyTreeQueue;

/**
 * Abstract of an enqueue event, containing information like
 * what is enqueued, the enqueue operation result, etc.
 *
 * @author WangXiao
 * @version 1.0
 */
public class EnqueueEvent {
    
    public static final EnqueueEvent EMPTY = null; // means there will be no more objects to be enqueued

    /**
     * Constructor.
     */
    public EnqueueEvent(ReplyTreeQueue replyTreeQueue, ReplyTree enqueuedReplyTree, boolean enqueuedSuccessfully) {
        this.replyTreeQueue = replyTreeQueue;
        this.enqueuedReplyTree = enqueuedReplyTree;
        this.enqueuedSuccessfully = enqueuedSuccessfully;
    }
    
    /**
     * Constructor.
     */
    public EnqueueEvent(ReplyTreeQueue replyTreeQueue, ReplyTreeNode enqueuedReplyTreeNode, boolean enqueuedSuccessfully) {
        this.replyTreeQueue = replyTreeQueue;
        this.enqueuedReplyTreeNode = enqueuedReplyTreeNode;
        this.enqueuedSuccessfully = enqueuedSuccessfully;
    }
    
    public ReplyTreeQueue getReplyTreeQueue() {
        return replyTreeQueue;
    }
    
    public ReplyTree getEnqueuedReplyTree() {
        if (this.enqueuedReplyTree == null) {
            throw new UnsupportedOperationException("Maybe you should use getEnqueuedReplyTreeNode()");
        }
        return enqueuedReplyTree;
    }
    
    public ReplyTreeNode getEnqueuedReplyTreeNode() {
        if (this.enqueuedReplyTreeNode == null) {
            throw new UnsupportedOperationException("Maybe you should use getEnqueuedReplyTree()");
        }
        return enqueuedReplyTreeNode;
    }
    
    public boolean isEnqueuedSuccessfully() {
        return enqueuedSuccessfully;
    }
    
    public boolean isReplyTreeEnqueued() {
        return this.enqueuedReplyTree != null;
    }
    
    public boolean isReplyTreeNodeEnqueued() {
        return this.enqueuedReplyTreeNode != null;
    }

    //////////////////////////////////////////////////////////////////////////////

    private ReplyTreeQueue replyTreeQueue;
    private ReplyTree enqueuedReplyTree;
    private ReplyTreeNode enqueuedReplyTreeNode;
    private boolean enqueuedSuccessfully;

}
